<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/25
 * Time: 15:01
 */
namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

class Feedback extends Api {
	protected $noNeedRight = '*';
	
	public function index(){
		$rows = Db::name('feedback')
			->where(['user_id' => $this->auth->id])
			->field('id, content, from_unixtime(create_time) as time, reply')
			->select();
		$this->success('查询成功', $rows);
	}
	
	public function add(){
		$content = input('post.content');
		!$content && $this->error('请输入反馈内容');
		
		$model = new \app\common\model\Feedback();
		$res = $model->isUpdate(false)
			->save([
				'user_id' => $this->auth->id,
				'content' => $content
			]);
		
		if($res) {
			$this->success('提交成功');
		} else {
			$this->error('提交出错，请稍候重试');
		}
	}
}